<?php
declare(strict_types=1);

namespace App\Controller\Chat\Ws;


use App\Controller\AbstractController;
use App\Service\Chat\ChatService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\WebSocketServer\Context;


/**
 * 消息控制器
 * Class MessageController
 * @package App\Controller\Chat\Ws
 * @Controller(prefix="chat",server="ws")
 */
class ChatController extends AbstractController
{


    /**
     * 发送消息
     * @RequestMapping(path="heartbeat",methods="GET")
     * @param array $payload
     */
    public function heartbeat($payload = [])
    {

    }

    /**
     * 会话列表
     * @RequestMapping(path="chatLists",methods="GET")
     * @return array
     */
    public function chat_lists()
    {
        $user_info = Context::get('user_info');

        $chat_list = ChatService::getInstance()->getUserChatLists($user_info['id']);

        return [
            [
                'user_id' => $user_info['id'],
                'cmd' => 'chatList',
                'payload' => $chat_list
            ]
        ];
    }

    /**
     * 会话列表
     * @RequestMapping(path="chatData",methods="GET")
     */
    public function chatData($payload = []): array
    {
        $user_info = Context::get('user_info');
        $chat= ChatService::getInstance()->getUserChat($user_info['id'],$payload['chat_id']);
        return [
            [
                'user_id' => $user_info('id'),
                'cmd' => 'chatData',
                'payload' => $chat
            ]
        ];
    }


}

